#!/bin/sh /etc/rc.common

START=99
USE_PROCD=1
NAME=fail2banop
 
get_config() {
  config_get_bool enabled $1 enabled 0
  config_get window $1 window 600
  config_get threshold $1 threshold 10
  config_get ban_duration $1 ban_duration 1440
}

start_service() { 
  config_load "$NAME"
  config_foreach get_config "$NAME"
  [ $enabled != 1 ] && return 1

  procd_open_instance
  procd_set_param command /usr/sbin/fail2ban_op_bin \
    --window="$window" \
    --threshold="$threshold" \
    --ban-duration="$ban_duration"
  procd_set_param stderr 1
  procd_set_param respawn
  procd_close_instance
}

stop_service() {
  nft flush set inet fw4 fail2banop4
  nft flush set inet fw4 fail2banop6
}

service_triggers() {
  procd_add_reload_trigger "$NAME"
}

